package com.shanghaionstar.nav.share;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.widget.Toast;

import com.onstar.cn.common.util.CommonUtil;
import com.onstar.cn.framework.mvp.base.core.BaseActivity;
import com.shanghaionstar.R;
import com.shanghaionstar.enumtype.FunctionNameFindId;
import com.shanghaionstar.share.AbstractShareDialog;
import com.shanghaionstar.utils.AlertDialogUtil;
import com.shanghaionstar.utils.BusinessUtil;
import com.shanghaionstar.utils.ShareWXUtil;
import com.tencent.mm.opensdk.modelmsg.SendMessageToWX;


/**
 * Created by Yonglang Hong on 2016/7/22.
 */
public class ShareFootPrintDialog extends AbstractShareDialog {
    private View view;
    private BaseActivity baseActivity;

    String url, title, content;

    public ShareFootPrintDialog(Context context, int theme, View view) {
        super(context, theme);
        baseActivity = (BaseActivity) context;
    }

    public ShareFootPrintDialog(Context context, int theme) {
        super(context, theme);
        baseActivity = (BaseActivity) context;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public ShareFootPrintDialog(Context context, boolean cancelable, OnCancelListener cancelListener, View view) {
        super(context, cancelable, cancelListener);
        baseActivity = (BaseActivity) context;
    }

    //分享到微信好友
    @Override
    public void shareToWX() {
        BusinessUtil.sendReportByClickType(baseActivity, FunctionNameFindId.Footprint_Wechat.getStringValue());
        if (!CommonUtil.checkNetWorkState(context)) {
            Toast.makeText(context, context.getResources().getString(R.string.networkError),
                    Toast.LENGTH_LONG).show();
        }

        if (!weiXinApi.isWXAppInstalled()) {
            Intent intent = new Intent();
            intent.setAction("android.intent.action.VIEW");
            Uri content_url = Uri.parse("http://weixin.qq.com");
            intent.setData(content_url);
            context.startActivity(intent);
        } else {
            new ShareWXUtil().shareToWX(baseActivity, weiXinApi, SendMessageToWX.Req.WXSceneSession, url, title, content, R.drawable.footprint_icon);
        }
    }

    //微信朋友圈
    @Override
    public void shareToWXF() {
        BusinessUtil.sendReportByClickType(baseActivity, FunctionNameFindId.Footprint_Moments.getStringValue());
        if (!CommonUtil.checkNetWorkState(context)) {
            Toast.makeText(context, context.getString(R.string.networkError), Toast.LENGTH_LONG)
                    .show();
        }
        if (!weiXinApi.isWXAppInstalled()) {
            Intent intent = new Intent();
            intent.setAction("android.intent.action.VIEW");
            Uri content_url = Uri.parse("http://weixin.qq.com");
            intent.setData(content_url);
            context.startActivity(intent);
        } else {
            // 检测微信版本 4.2以上的 才支持分享到朋友圈 版本过低 提示用户下载
            if (weiXinApi.getWXAppSupportAPI() < 0x21020001) {
                AlertDialogUtil.showAlertDialog(context, "",
                        context.getString(R.string.weixin_version_too_old));
            } else {
                new ShareWXUtil().shareToWX(baseActivity, weiXinApi, SendMessageToWX.Req.WXSceneTimeline, url, title, content, R.drawable.footprint_icon);
            }
        }
    }

}
